package com.example.bms.mapper;
import com.example.bms.entity.Replay;
import org.apache.ibatis.annotations.*;
import java.util.List;


/**
 * @apiNote 回复记录的增删改查
 * @author 武子砚
 * @email 2681413363@qq.com
 * @since 1.0.0
 */
@Mapper
public interface ReplayMapper {


    /**
     * @apiNote 查询所有回复记录
     * @author 武子砚
     * - messageId 消息Id
     * - replayId 回复Id
     * - replay 回复消息
     * - replayTime 回复时间
     * @email 2681413363@qq.com
     * @return List<Replay>
     * @since 1.0.0
     */
    @Select("select messageId,replayId,replay,replayTime from replay")
    List<Replay> findAll();


    /**
     * @apiNote 根据消息Id查询回复记录
     * @author 武子砚
     * @param messageId  消息Id
     * - messageId 消息Id
     * - replayId 回复Id
     * - replay 回复消息
     * - replayTime 回复时间
     * @email 2681413363@qq.com
     * @return List<Replay>
     * @since 1.0.0
     */
    @Select("select messageId,replayId,replay,replayTime from replay where messageId = #{messageId}")
    List<Replay> findAllById(Integer messageId);


    /**
     * @apiNote 根据消息Id查询回复记录
     * @param messageId 消息id
     * @author 武子砚
     * - messageId 消息Id
     * - replayId 回复Id
     * - replay 回复消息
     * - replayTime 回复时间
     * @email 2681413363@qq.com
     * @return Replay
     * @since 1.0.0
     */
    @Select("select messageId,replayId,replay,replayTime from replay where messageId = #{messageId}")
    Replay findById(Integer messageId);


    /**
     * @apiNote 删除回复记录
     * @author 武子砚
     * @email 2681413363@qq.com
     * @return Replay对象
     * @since 1.0.0
     */
    @Delete("delete from replay where replayId = #{replayId}")
    int delete(Integer replayId);


    /**
     * @apiNote 修改回复记录
     * @author 武子砚
     * - title 话题
     * - replay 回复消息
     * - replayTime 回复时间
     * @email 2681413363@qq.com
     * @return int类型，表示受影响的数据
     * @since 1.0.0
     */
    @Update("update replay set title = #{title}, replay = #{replay}, replayTime = #{replayTime} where replayId = #{replayId}")
    int update(Replay replay);


    /**
     * @apiNote 插入回复记录
     * @author 武子砚
     * - messageId 消息Id
     * - replay 回复消息
     * - replayTime 回复时间
     * @email 2681413363@qq.com
     * @return int类型，表示受影响的条数
     * @since 1.0.0
     */
    @Options(useGeneratedKeys = true,keyProperty = "replayId")
    @Insert("insert into replay(messageId,replay,replayTime) values(#{messageId}, #{replay},#{replayTime})")
    int add(Replay replay);
}
